package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbFlowCompVplPdm;
import com.sailfish.springbootdemo.pojo.db7.TbFlowProcessDetail;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;


public interface TbFlowCompVplPdmDao {

    /**
    @Results(id = "compVplPdmMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "flow_no", property = "flow_no", jdbcType = JdbcType.VARCHAR),
            @Result(column = "flow_level", property = "flow_level", jdbcType = JdbcType.INTEGER),
            @Result(column = "DocumentName", property = "DocumentName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "s1partnumber", property = "s1partnumber", jdbcType = JdbcType.VARCHAR),
            @Result(column = "S1PCBENCPFILENAME", property = "S1PCBENCPFILENAME", jdbcType = JdbcType.VARCHAR),
            @Result(column = "s1partdescelements", property = "s1partdescelements", jdbcType = JdbcType.VARCHAR),
            @Result(column = "h3productline", property = "h3productline", jdbcType = JdbcType.VARCHAR),
            @Result(column = "h3product", property = "h3product", jdbcType = JdbcType.VARCHAR),
            @Result(column = "priority", property = "priority", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "create_time", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "create_user", property = "create_user", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_time", property = "update_time", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_user", property = "update_user", jdbcType = JdbcType.VARCHAR)
    })*/

    @Insert("<script>" +
            "insert into " + DB7TableName.TB_FLOW_COMP_VPL_PDM + " " +
            "( "+
            "flow_no, " +
            "flow_level, " +
            "create_time, " +
            "create_user, " +
            "update_time, " +
            "update_user, " +
            "DocumentName, " +
            "s1partnumber, " +
            "S1PCBENCPFILENAME, " +
            "s1partdescelements, " +
            "h3productline, " +
            "h3product, " +
            "priority " +
            ")"+
            "values "+
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            "(" +
            "#{entity.flow_no}, " +
            "#{entity.flow_level}, " +
            "#{entity.create_time}, " +
            "#{entity.create_user}, " +
            "#{entity.update_time}, " +
            "#{entity.update_user}, " +
            "#{entity.DocumentName}, " +
            "#{entity.s1partnumber}, " +
            "#{entity.S1PCBENCPFILENAME}, " +
            "#{entity.s1partdescelements}, " +
            "#{entity.h3productline}, " +
            "#{entity.h3product}, " +
            "#{entity.priority} " +
            ")"+
            "</foreach>"+
            "</script>"
    )
    Integer insertTbFlowCompVplPdmBatch(@Param("entities") List<TbFlowCompVplPdm> entities);


    @Update("<script>" +
            "update " + DB7TableName.TB_FLOW_COMP_VPL_PDM + " " +
            "set " +
            " <if test='entity.update_time != null'>update_time = #{entity.update_time},</if>" +
            " <if test='entity.update_user != null'>update_user = #{entity.update_user},</if>" +
            " <if test='entity.DocumentName != null'>DocumentName = #{entity.DocumentName},</if>" +
            " <if test='entity.s1partnumber != null'>s1partnumber = #{entity.s1partnumber},</if>" +
            " <if test='entity.S1PCBENCPFILENAME != null'>S1PCBENCPFILENAME = #{entity.S1PCBENCPFILENAME},</if>" +
            " <if test='entity.s1partdescelements != null'>s1partdescelements = #{entity.s1partdescelements},</if>" +
            " <if test='entity.h3productline != null'>h3productline = #{entity.h3productline},</if>" +
            " <if test='entity.h3product != null'>h3product = #{entity.h3product},</if>" +
            " <if test='entity.priority != null'>priority = #{entity.priority},</if>" +
            " update_time = #{entity.update_time}," +
            " update_user = #{entity.update_user}" +
            " where id = #{entity.id}" +
            //" where flow_no = #{entity.flow_no} and flow_level = #{entity.flow_level}" +
            "</script>"
    )
    Integer updateTbFlowCompVplPdm(@Param("entity") TbFlowCompVplPdm entity);


    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL_PDM + " " +
            "where id = #{id}" +
            "</script>"
    )
    Integer deleteTbTbFlowCompVplPdm(@Param("id") Integer id);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL_PDM + " " +
            "where flow_no = #{flow_no}" +
            "</script>"
    )
    Integer deleteTbTbFlowCompVplPdmByFlowNo(@Param("flow_no") String flow_no);

    @Select("<script>" +
            "select " +
            "* " +
            "from " + DB7TableName.TB_FLOW_COMP_VPL_PDM + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    //@ResultMap(value = "compVplPdmMap")
    List<TbFlowCompVplPdm> getTbFlowCompVplPdmByFlowNo(@Param("flowNo") String flowNo,
                                                       @Param("flowLevel") Integer flowLevel);

    @Select("<script>" +
            "select * from " + DB7TableName.TB_FLOW_COMP_VPL_PDM + " " +
            "where 1=1" +
            "   <if test='tbFlowCompVplPdm.DocumentName != null'>and DocumentName like CONCAT('%',#{tbFlowCompVplPdm.DocumentName},'%')</if>" +
            "   <if test='tbFlowCompVplPdm.S1PCBENCPFILENAME != null'>and S1PCBENCPFILENAME like CONCAT('%',#{tbFlowCompVplPdm.S1PCBENCPFILENAME},'%')</if>" +
            "</script>"
    )
    List<TbFlowCompVplPdm> getTbFlowCompVplPdm(@Param("tbFlowCompVplPdm")TbFlowCompVplPdm tbFlowCompVplPdm);

    @Select("<script>" +
            "select * from " + DB7TableName.TB_FLOW_COMP_VPL_PDM + " " +
            "where 1=1" +
            "   <if test='tbFlowCompVplPdm.flow_no != null'>and flow_no = #{tbFlowCompVplPdm.flow_no}</if>" +
            "   <if test='tbFlowCompVplPdm.DocumentName != null'>and DocumentName = #{tbFlowCompVplPdm.DocumentName}</if>" +
            "   <if test='tbFlowCompVplPdm.S1PCBENCPFILENAME != null'>and S1PCBENCPFILENAME = #{tbFlowCompVplPdm.S1PCBENCPFILENAME}</if>" +
            "</script>"
    )
    List<TbFlowCompVplPdm> getTbFlowCompVplPdm2(@Param("tbFlowCompVplPdm")TbFlowCompVplPdm tbFlowCompVplPdm);

}




